package org.artifact.core.context.bytebuf;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;

public class NettyByteBuf extends IByteBuff {

	private ByteBuf buf = null;
	
	public NettyByteBuf(ByteBuf buf) {
		this.buf = buf;
	}
	
	@Override
	public void onWriteBytes(byte[] value) {
		buf.writeBytes(value);
	}

	@Override
	public void onWriteByte(byte value) {
		buf.writeByte(value);
	}

	@Override
	public void onWriteShort(short value) {
		buf.writeShort(value);
	}

	@Override
	public void onWriteInt(int value) {
		buf.writeInt(value);
	}

	@Override
	public void onWriteLong(long value) {
		buf.writeLong(value);
	}

	@Override
	public void onWriteFloat(float value) {
		buf.writeFloat(value);
	}

	@Override
	public void onWriteDouble(double value) {
		buf.writeDouble(value);
	}

	@Override
	public void onWriteBoolean(boolean value) {
		buf.writeBoolean(value);
	}

	@Override
	public byte[] onReadBytes(int length) {
		byte[] data = new byte[length];
		buf.readBytes(data);
		return data;
	}

	@Override
	public byte onReadByte() {
		return buf.readByte();
	}

	@Override
	public short onReadShort() {
		return buf.readShort();
	}

	@Override
	public int onReadInt() {
		return buf.readInt();
	}

	@Override
	public long onReadLong() {
		return buf.readLong();
	}

	@Override
	public float onReadFloat() {
		return buf.readFloat();
	}

	@Override
	public double onReadDouble() {
		return buf.readDouble();
	}

	@Override
	public boolean onReadBoolean() {
		return buf.readBoolean();
	}

	@Override
	public void clear() {
		buf.clear();
	}

	@Override
	public int getReaderIndex() {
		return buf.readerIndex();
	}

	@Override
	public void setReaderIndex(int readerIndex) {
		buf.readerIndex(readerIndex);
	}

	@Override
	public int getWriterIndex() {
		return buf.writerIndex();
	}

	@Override
	public void setWriterIndex(int writerIndex) {
		buf.writerIndex(writerIndex);
	}
	
	@Override
	public int readableBytes() {
		return buf.readableBytes();
	}

	@Override
	public void skipBytes(int length) {
		buf.skipBytes(length);
	}

	@Override
	public byte getTag() {
		return buf.getByte(buf.readerIndex());
	}

	@Override
	public byte[] array() {
		return ByteBufUtil.getBytes(buf);
	}
}
